package My_Workers;

import java.lang.reflect.Field;

import org.jboss.aop.joinpoint.FieldWriteInvocation;

public class ObserverAspect
{
   public Object fieldChanged(FieldWriteInvocation invocation) throws Throwable
   {
      Observable target = (Observable)invocation.getTargetObject();
      Field fld = invocation.getField();
      String fieldName = fld.getName();
      fld.setAccessible(true);
      Object oldVal = invocation.getField().get(target);
      Object result = invocation.invokeNext();
      Object newVal = invocation.getField().get(target);
      
      target.notifyObservers("Changed " + fieldName + " from " + oldVal + " to " + newVal);

      return result;
   }
}
